﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using KardexSist.UserControls.Common;
using Kardex_Common;
using Kardex_BussinesLogic;
using Kardex_Entity;
using KardexSist.Library;

namespace KardexSist.UserControls.PreSale
{
    public partial class CtrlMainPresale : CtrlMainBase, IOperations
    {
        private List<person> ListPreSale;
        private IOperations IOperatioSingle;

        public CtrlMainPresale()
        {
            InitializeComponent();
            ctrlPreSale1.MostrarListaClick += LoadGrid;
            IOperatioSingle = (IOperations)ctrlPreSale1;  
        }
        private void LoadGrid()
        {
            try
            {
                PreventistaFactory d = new  PreventistaFactory();
                ListPreSale = d.GetListPreventista();
                grdPreventista.DataSource = ListPreSale;
                FormatColumns();
            }
            catch (Exception ex)
            {
                Util.MessageBoxShow(Util.Enum_TypeMessage.ErrorExecption, ex);
            }
        }
        private void FormatColumns()
        {
            grvPreventista.Columns["IdPerson"].Visible = false;
            grvPreventista.Columns["centrodistribucion"].Visible = false;
            grvPreventista.Columns["distribuidor"].Visible = false;
            grvPreventista.Columns["lugarciexpedido"].Visible = false;
            grvPreventista.Columns["client"].Visible = false;            
            grvPreventista.Columns["supervisor"].Visible = false;
            grvPreventista.Columns["lugarciexpedido"].Visible = false;
            grvPreventista.Columns["preventista"].Visible = false;


            grvPreventista.Columns["Name"].Caption = "Nombre";
            grvPreventista.Columns["Name"].VisibleIndex = 0;


            grvPreventista.Columns["CI"].Caption = "CI";
            grvPreventista.Columns["CI"].VisibleIndex = 1;

            grvPreventista.Columns["IdTipoCIExpedido"].Caption = "Expedido";
            grvPreventista.Columns["IdTipoCIExpedido"].VisibleIndex = 2;

            grvPreventista.Columns["IdCD"].Caption = "Centro Dist.";
            grvPreventista.Columns["IdCD"].VisibleIndex = 3;

            grvPreventista.Columns["Telephone"].Caption = "Telefono";
            grvPreventista.Columns["Telephone"].VisibleIndex = 4;

        }


        public void Add()
        {
            IOperatioSingle.Add();
        }

        public void Delete()
        {
            IOperatioSingle.Delete();
        }

        public void Save()
        {
            IOperatioSingle.Save();
        }

        public void Export()
        {
            Utils.ExportGridView(grvPreventista); 
        }

        private void grvPreventista_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            object objPreventista = grvPreventista.GetFocusedRow();
            if (objPreventista != null)
            {
                person personCurrent = new person() { preventista = new preventista() };
                var obj = (person)objPreventista;
                personCurrent.IdCD = obj.IdCD;
                personCurrent.IdPerson = obj.IdPerson;
                personCurrent.IdTipoCIExpedido = obj.IdTipoCIExpedido;
                personCurrent.Name = obj.Name;
                personCurrent.Telephone = obj.Telephone;
                personCurrent.Activ = obj.Activ;
                personCurrent.CI = obj.CI;
                personCurrent.preventista.CodigoHH = obj.preventista.CodigoHH;
                personCurrent.preventista.IdPerson = obj.IdPerson;
                 ctrlPreSale1.TrigerObjPerson(personCurrent);
            } 

        }
    }
}
